package com.example.dell.fastshopping.order.model;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.example.dell.fastshopping.network.ApiService;
import com.example.dell.fastshopping.network.NetCallback;
import com.example.dell.fastshopping.network.RetrofitClient;
import com.example.dell.fastshopping.network.http.BaseResponse;
import com.example.dell.fastshopping.order.OrderInfo;

import java.util.HashMap;
import java.util.List;

import retrofit2.http.Query;

public class OrderViewModel extends ViewModel {
    private ApiService service = RetrofitClient.getInstance().create(ApiService.class);
    private MutableLiveData<List<OrderInfo>> orderList = new MutableLiveData();

    public MutableLiveData<List<OrderInfo>> getOrderList(int pageNum, int pageSize, Integer status) {
        if (status == -1) {
            status = null;
        }

        RetrofitClient.execute(service.getOrderList(pageNum, pageSize, status), new NetCallback<BaseResponse<OrderInfo>>() {
            @Override
            public void netCallback(BaseResponse<OrderInfo> baseResponse) {

                orderList.setValue(baseResponse.getData().getList());
            }
        });
        return orderList;
    }
}
